package com.infomanage.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.infomanage.bean.SearchBean;
import com.infomanage.exception.DaoException;
import com.infomanage.po.HibernateSessionFactory;
import com.infomanage.po.Message;


public class MessageDAO extends BaseDAO<Message> {
	public Message find(int id) throws DaoException{
		return super.find(Message.class, id);
	}
	@SuppressWarnings("unchecked")
	public List<Message> findAll() throws DaoException {
		return super.findAll(Message.class);
	}
	
	@SuppressWarnings("unchecked")
	public List<Message> findByFields(SearchBean searchBean) throws DaoException {
		return super.findByFields(Message.class, searchBean);
	}
	
	
	public int count(SearchBean searchBean) throws DaoException{
		return super.count(Message.class, searchBean);
	}
	
	public Message findByState() throws DaoException{
		Session session = HibernateSessionFactory.getSession();
		List<Message> list = null;
		try {
			Query query =  session.createQuery("from Message where state = 1");
			list = query.list();
		} catch (Exception e) {
			throw new DaoException(e);
		} finally {
			HibernateSessionFactory.closeSession();
		}
		return (list == null || list.size()==0) ? null : list.get(0);
	}
	
}